function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}
function trim(val) {
  return val.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
class Router {
    navto(obj) {
        wx.navigateTo({
            url: obj.url,
            success: function (res) {
                // success
                if (obj.data) {
                    setTimeout(() => {
                        let pages = getCurrentPages()
                        let curPage = pages[pages.length - 1];
                        if(curPage.startPageForData) {
                            curPage.startPageForData(obj.data);
                        } else {
                            curPage.setData({
                              options:obj.data
                            });
                        }   
                    }, 1000);
                }
            },
            fail: function (err) {
                // fail
                obj.fail && obj.fail(res);
            },
            complete: function () {
                // complete
                obj.complete && obj.complete();
            }
        });
    }
}
Router = new Router();
module.exports = {
  formatTime: formatTime,
  Router:Router,
  trim: trim
}
